package com.tanhua.server.controller;

import com.tanhua.domain.db.Settings;
import com.tanhua.server.service.SettingsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * 通用设置控制器
 */
@RestController
@RequestMapping("/users")
@Slf4j
public class SettingsController {

    @Autowired
    private SettingsService settingsService;


    /**
     * 接口名称：用户通用设置 - 读取
     * 接口路径：GET/users/settings
     */
    @GetMapping("settings")
    public ResponseEntity<Object> settings(){
        log.info("接口名称：用户通用设置 - 读取");
        return settingsService.querySettings();
    }

    /**
     * 接口名称：通知设置 - 保存
     * 接口路径：POST/users/notifications/setting
     */
    @PostMapping("notifications/setting")
    public ResponseEntity<Object> saveNotification(@RequestBody Settings settings){
        log.info("接口名称：通知设置 - 保存");
        return settingsService.saveNotification(settings);
    }

    /**
     * 接口名称：设置陌生人问题 - 保存
     * 接口路径：POST/users/questions
     */
    @PostMapping("questions")
    public ResponseEntity<Object> saveQuestion(@RequestBody Map<String, String> param){
        log.info("接口名称：设置陌生人问题 - 保存");
        String content = param.get("content");
        return settingsService.saveQuestion(content);
    }

    /**
     * 接口名称：黑名单 - 翻页列表
     * 接口路径：GET/users/blacklist
     */
    @GetMapping("blacklist")
    public ResponseEntity<Object> blacklist(@RequestParam(defaultValue = "1") Integer page,
                                            @RequestParam(defaultValue = "10") Integer pagesize){
        log.info("接口名称：黑名单 - 翻页列表");
        return settingsService.blacklist(page, pagesize);
    }

    /**
     * 接口名称：黑名单 - 移除
     * 接口路径：DELETE/users/blacklist/:uid
     */
    @DeleteMapping("blacklist/{uid}")
    public ResponseEntity<Object> deleteBlackUser(@PathVariable Long uid){
        log.info("接口名称：黑名单 - 移除");
        return settingsService.deleteBlackUser(uid);
    }
}
